//true:ios false:android
var sys;
var notificationEnabled=false;//消息推送开启
var vibrateStatus=true;//震动提醒
var preOrderAwaitConfirm=3;//默认预订单等待确认
var bell=0;//默认铃声

const remindCountMap=new Map([
		[0,"不提醒"],
		[1,"1次"],
		[3,"3次(推荐)"]
	]);
	
const bellMap=new Map([
	[0,"经典女声版"],
	[1,"粤语方言"],
	[2,"成都话方言"]
]);

function checkSystem(){
	//#ifdef APP-PLUS
	if(uni.getSystemInfoSync().platform==='ios'){
		sys=true;
	}else if(uni.getSystemInfoSync().platform==='android'){
		sys=false;
	}
	//#endif
}

function checkNotificationPermit(){
	let res=false;
	//#ifdef APP-PLUS
	if(sys){
		var UIApplication = plus.ios.import("UIApplication");
		var app = UIApplication.sharedApplication();  
		var enabledTypes  = 0;  
		if (app.currentUserNotificationSettings) {  
		    var settings = app.currentUserNotificationSettings();  
		    enabledTypes = settings.plusGetAttribute("types");  
		} else {  
		    //针对低版本ios系统  
		    enabledTypes = app.enabledRemoteNotificationTypes();  
		}  
		plus.ios.deleteObject(app);  
		if(0!=enabledTypes){
			res=true;
		}
	}else {
		var main = plus.android.runtimeMainActivity();  
		var pkName = main.getPackageName();  
		var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");  
		var packageNames = NotificationManagerCompat.from(main);
		if(packageNames.areNotificationsEnabled()){
			res=true;
		}
	}
	//#endif
	return res;
}

checkSystem()
notificationEnabled=checkNotificationPermit()
//初始化消息铃声设置
uni.getStorage({
	key:"vibrateStatus",
	success(e){
		vibrateStatus=e.data;
	},
	fail(e) {
		uni.setStorage({
			key:"vibrateStatus",
			data:vibrateStatus
		})
	}
});
uni.getStorage({
	key:"preOrderAwaitConfirm",
	success(e){
		preOrderAwaitConfirm=e.data;
	},
	fail(e) {
		uni.setStorage({
			key:"preOrderAwaitConfirm",
			data:preOrderAwaitConfirm
		})
	}
});
uni.getStorage({
	key:"bell",
	success(e){
		bell=e.data;
	},
	fail(e) {
		uni.setStorage({
			key:"bell",
			data:bell
		})
	}
});


export default{
	sys:sys,
	notificationEnabled:notificationEnabled,
	vibrateStatus:vibrateStatus,
	preOrderAwaitConfirm:preOrderAwaitConfirm,
	bell:bell,
	bellMap:bellMap,
	remindMap:remindCountMap,
	checkNotificationPermit,
	setNotificationEnabled(enabled){
		console.log("#########"+this.notificationEnabled)
		this.notificationEnabled=enabled;
	},
	setVibrateStatus(status){
		this.vibrateStatus=status;
		uni.setStorage({
			key:"vibrateStatus",
			data:status
		})
	},
	setPreOrderAwaitConfirm(e){
		this.preOrderAwaitConfirm=e;
		uni.setStorage({
			key:"preOrderAwaitConfirm",
			data:e
		})
	},
	setBell(e){
		this.bell=e;
		uni.setStorage({
			key:"bell",
			data:e
		})
	}
}